package pw.yumc.Residence.commandsub;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import com.bekvon.bukkit.residence.protection.FlagPermissions;
import com.bekvon.bukkit.residence.protection.PermissionListManager;

import cn.citycraft.PluginHelper.commands.BaseCommand;
import pw.yumc.Residence.ResidenceMain;
import pw.yumc.Residence.text.Language;

public class CommandLists extends BaseCommand {
    ResidenceMain plugin;

    public CommandLists(final ResidenceMain plugin) {
        super();
        this.plugin = plugin;
        setMinimumArguments(1);
        setOnlyPlayerExecutable();
        setPossibleArguments("用法: /res lists ? 查看帮助");
    }

    @Override
    public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
        final Player player = (Player) sender;
        final boolean resadmin = (command != null);
        final Language language = plugin.getLanguage();
        final PermissionListManager pmanager = plugin.getPermissionListManager();
        final String listname = args[1];

        switch (args[0]) {
        case "list":
            pmanager.printLists(player);
            return;
        case "add":
            if (args.length == 2) {
                pmanager.makeList(player, listname);
            }
            return;
        case "remove":
            if (args.length == 2) {
                pmanager.removeList(player, listname);
            }
            return;
        case "apply":
            if (args.length == 3) {
                pmanager.applyListToResidence(player, listname, args[2], resadmin);
            }
            return;
        case "set":
            if (args.length == 4) {
                pmanager.getList(player.getName(), listname).setFlag(args[2], FlagPermissions.stringToFlagState(args[3]));
                player.sendMessage(ChatColor.GREEN + language.getPhrase("FlagSet"));
            }
            return;
        case "pset":
            if (args.length == 5) {
                pmanager.getList(player.getName(), listname).setPlayerFlag(args[2], args[3], FlagPermissions.stringToFlagState(args[4]));
                player.sendMessage(ChatColor.GREEN + language.getPhrase("FlagSet"));
            }
            return;
        case "gset":
            if (args.length == 5) {
                pmanager.getList(player.getName(), listname).setGroupFlag(args[2], args[3], FlagPermissions.stringToFlagState(args[4]));
                player.sendMessage(ChatColor.GREEN + language.getPhrase("FlagSet"));
            }
            return;
        case "view":
            if (args.length == 2) {
                pmanager.printList(player, listname);
            }
            return;
        }
    }

}
